package zuoye3;

/**
 * 编程统计字符串"ABCD123!@#$%ab"中大写字母、小写字母、数字、其它字符的个数并打 印出来。
 */
public class NumberOfStatistics {
    public static void main(String[] args) {
        String upperCaseReg = "[A-Z]";
        String lowerCaseReg = "[a-z]";
        String numberReg = "[0-9]";
        String otherReg = "[^0-9A-Za-z]";
        int upperCaseCount = 0;
        int lowerCaseCount = 0;
        int numberCount = 0;
        int otherCount = 0;
        String a ="ABCD123!@#$%ab";
        for (int i=0;i<a.length();i++) {
            String b = a.substring(i,i+1);
            if (b.matches(upperCaseReg)) {
                upperCaseCount++;
            }
            if (b.matches(lowerCaseReg)) {
                lowerCaseCount++;
            }
            if (b.matches(numberReg)) {
                numberCount++;
            }
            if (b.matches(otherReg)) {
                otherCount++;
            }
        }
        System.out.println("ABCD123!@#$%ab大写字母个数" + upperCaseCount);
        System.out.println("ABCD123!@#$%ab小写字母个数" + lowerCaseCount);
        System.out.println("ABCD123!@#$%ab数字个数" + numberCount);
        System.out.println("ABCD123!@#$%ab其他字符个数" + otherCount);
    }
}
